package com.xy.controller.mainData;

import com.xy.api.model.dto.mainData.ProductInstanceDTO;
import com.xy.api.model.request.mainData.ProductRequest;
import com.xy.api.model.request.mainData.SubmitProductInstanceRequest;
import com.xy.api.model.response.R;
import com.xy.api.model.response.Rows;
import com.xy.api.service.mainData.IProductInstanceService;
import com.xy.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/product/instance")
public class ProductInstanceController extends BaseController {

    @Autowired
    private IProductInstanceService productInstanceService;

    @PostMapping("/queryList")
    public R queryList(@RequestBody ProductRequest request) {
        Rows<ProductInstanceDTO> rows = productInstanceService.queryProductInstanceList(request);
        return success(rows);
    }

    @PostMapping("/saveList")
    public R saveList(@RequestBody SubmitProductInstanceRequest request) {
        productInstanceService.saveProductInstanceList(request);
        return success();
    }

    @PostMapping("/delete")
    public R deleteProductInstance(@RequestBody ProductInstanceDTO request) {
        productInstanceService.deleteProductInstance(request.getId());
        return success();
    }
}